import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FindSubsequences {

    List<Integer> list = new ArrayList<>();
    List<List<Integer>> ans = new ArrayList<>();
    Set<List<Integer>> set = new HashSet<>();
    public List<List<Integer>> findSubsequences(int[] nums) {
        dfs1(0, nums, Integer.MIN_VALUE);
        return new ArrayList<>(set);
    }

    public void dfs(int i, int[] nums, int last) {
        if (i == nums.length) {
            if (list.size() > 1) {
                ans.add(new ArrayList<>(list));
            }
            return;
        }

        if (nums[i] != last) dfs(i + 1, nums, last);
        if (nums[i] >= last) {
            list.add(nums[i]);
            dfs(i + 1, nums, nums[i]);
            list.remove(list.size() - 1);
        }
    }

    public void dfs1(int i, int[] nums, int last) {
        if (i == nums.length) {
            if (list.size() > 1) {
                set.add(new ArrayList<>(list));
            }
            return;
        }

        dfs1(i + 1, nums, last);
        if (nums[i] >= last) {
            list.add(nums[i]);
            dfs(i + 1, nums, nums[i]);
            list.remove(list.size() - 1);
        }
    }
}
